package tp.pr4;

import java.awt.Color;

import tp.pr4.gui.MapCell;
import tp.pr4.items.*;

public class Room
{

	private boolean exit;
	private String description;

	private ItemList listaItems;
	private String _name;
	
	private MapCell mapCell;

	
	public Room(boolean exit, String description)
	{
		this.exit=exit;
		this.description=description;
		this.listaItems=new ItemList();
	}
	public Room(boolean exit, String description,String name)
	{
		this.exit=exit;
		this.description=description;
		this._name=name;
		this.listaItems=new ItemList();
	}

	public Room(boolean exit, String description, Item[] items)
	{
		this.exit=exit;
		this.description=description;
		this.listaItems=new ItemList(items);
	}

	public boolean isExit()
	{
		boolean salida = this.exit;

		return salida;
	}


		public String getDescription(){
			String lista=this.listaItems.toString();
			String desc;
			if(lista==null)
			{
				desc=this.description+MensajesConst.roomVacio;
			}
			else 
			{
				desc=this.description+MensajesConst.roomItems+lista;
			}
			
			return  desc;
				
		}



	public boolean addItem(Item it)
	{
		return this.listaItems.add(it);
	}

	public boolean pickItem(Player who, String id)
	{
		boolean recoge=false;
		int posicion = this.listaItems.searchItem(id);
		
		if (posicion == -1) //al hacer que no retorne directamente es necesario el else
		{
			recoge=false;
		}
		else
		{
			Item item = this.listaItems.get(posicion);
			if (who.addItem(item))
			{
				this.listaItems.remove(posicion); //solo quita la referencia
				recoge=true;
			}
		}
		
		
		return recoge;
	}

	public boolean existsItem(String id)
	{

		return (this.listaItems.searchItem(id) != -1);
	}
	
	public void enterRoom(MapCell cell){
		cell.set_habitacion(this);
		cell.setBackground(Color.GREEN);
		cell.setText(this._name);
		this.mapCell=cell;
	}
	
	public void leaveRoom(){
		
		this.mapCell.setBackground(Color.GRAY);
	}
}